package com.yuwei.module_device

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.yuwei.module_device.adapter.DeviceAdapter
import com.yuwei.module_device.databinding.ActivityDeviceBinding
import com.yuwei.module_device.viewmodel.DeviceViewModel
/**
 * 智慧园区-01-设备管理V1.1-张亦婷-20250507
 */
@Route(path = RouterPath.MODULE_DEVICE_ACTIVITY)
class DeviceActivity : BaseMvvmActivity<ActivityDeviceBinding>() {
    lateinit var deviceAdapter: DeviceAdapter
    private val mViewModel:DeviceViewModel by viewModels()
    override fun initViews() {
        super.initViews()
        deviceAdapter= DeviceAdapter()
        binding.deviceRv.adapter=deviceAdapter
        binding.deviceRv.layoutManager=LinearLayoutManager(this)
        mViewModel.deviceList()
        binding.deviceBack.setOnClickListener {
            finish()
        }
        binding.deviceMore.setOnClickListener {
            ARouter.getInstance().build(RouterPath.MODULE_ADD_DEVICE_ACTIVITY).navigation()
        }
    }
    override fun observeDataChange() {
        mViewModel.getDeviceSuccess.observe(this){
            Log.d("TAG", "observeDataChange: ${it[0].deviceName}")
            deviceAdapter.data.clear()
            deviceAdapter.data.addAll(it)
            deviceAdapter.data.reverse()
            deviceAdapter.notifyDataSetChanged()
        }
    }

    override fun onResume() {
        super.onResume()
        mViewModel.deviceList()
    }
    override fun getLayoutId(): Int {
        return R.layout.activity_device
    }
}